#include "config.h"

int __height;
int __waveType;
int __waveSize;
int __waveSpeed;

Config *_config;
NSString* waveTypes[4] = {@"Smooth circle",@"Sharp circle",@"Sine ball",@"Cosine ball"};
NSString* waveSpeedsShort[3] = {@"Oil",@"Water",@"Mercury"};
NSString* waveSpeedsLong[3] = {@"Oil - (slow/HQ)",@"Water - (medium/MQ)",@"Mercury - (quick/LQ)"};

@implementation Config

+ (Config *) singleton
{
    if (!_config) {
        _config = [[Config alloc] init];
    }
    return _config;
}

- (id) init
{
	[super init];
	applicationID = CFStringCreateWithCString(NULL, "com.gnese.waves", kCFStringEncodingMacRoman);
	return self;
}
- (void)SaveDefaults
{
	CFPreferencesSetAppValue((CFStringRef)@"x", [NSNumber numberWithInt: _x], applicationID);
 	CFPreferencesSetAppValue((CFStringRef)@"y", [NSNumber numberWithInt: _y], applicationID);
	CFPreferencesSetAppValue((CFStringRef)@"waveheight", [NSNumber numberWithInt: __height], applicationID);
	CFPreferencesSetAppValue((CFStringRef)@"waveType", [NSNumber numberWithInt: __waveType], applicationID);
	CFPreferencesSetAppValue((CFStringRef)@"waveSize", [NSNumber numberWithInt: __waveSize], applicationID);
	CFPreferencesSetAppValue((CFStringRef)@"waveSpeed", [NSNumber numberWithInt: __waveSpeed], applicationID);
	CFPreferencesSetAppValue((CFStringRef)@"startedFromApp", [NSNumber numberWithInt: _startedFromApp], applicationID);
	CFPreferencesSetAppValue((CFStringRef)@"reminder", [NSNumber numberWithInt: _reminder], applicationID);

    // save to file
	CFPreferencesAppSynchronize(applicationID);
}

- (void)ResetDefaults
{
	_x = DEFAULT_x;
	_y = DEFAULT_y;
	__height = DEFAULT_height;
	__waveType = DEFAULT_waveType;
	__waveSize = DEFAULT_waveSize;
	__waveSpeed = DEFAULT_waveSpeed;
}

- (void)LoadDefaults
{
	
	[self ResetDefaults];
	_reminder = DEFAULT_reminder;
	CFPreferencesAppSynchronize(applicationID);
	
	NSNumber *nb;
	nb = (NSNumber*)CFPreferencesCopyAppValue((CFStringRef)@"x",applicationID); if (nb) _x = [nb intValue];
	nb = (NSNumber*)CFPreferencesCopyAppValue((CFStringRef)@"y",applicationID); if (nb) _y = [nb intValue];
	nb = (NSNumber*)CFPreferencesCopyAppValue((CFStringRef)@"waveheight",applicationID); if (nb) __height = [nb intValue];
	nb = (NSNumber*)CFPreferencesCopyAppValue((CFStringRef)@"waveType",applicationID); if (nb) __waveType = [nb intValue];
	nb = (NSNumber*)CFPreferencesCopyAppValue((CFStringRef)@"waveSize",applicationID); if (nb) __waveSize = [nb intValue];
	nb = (NSNumber*)CFPreferencesCopyAppValue((CFStringRef)@"waveSpeed",applicationID); if (nb) __waveSpeed = [nb intValue];
	nb = (NSNumber*)CFPreferencesCopyAppValue((CFStringRef)@"startedFromApp",applicationID); if (nb) _startedFromApp = [nb intValue];
	nb = (NSNumber*)CFPreferencesCopyAppValue((CFStringRef)@"reminder",applicationID); if (nb) _reminder = [nb intValue];
}

- (int) height { return __height; }
- heightSet: (int) height{
	__height = height;
}
- (int) waveType { return __waveType; }
- waveTypeSet: (int) waveType{
	__waveType = waveType;
}
- (int) waveSize { return __waveSize; }
- waveSizeSet: (int) waveSize{
	__waveSize = waveSize;
}
- (int) waveSpeed { return __waveSpeed; }
- waveSpeedSet: (int) waveSpeed{
	__waveSpeed = waveSpeed;
}
- (int) reminder { return _reminder; }
- reminderSet: (int) reminder{
	_reminder = reminder;
}
- (int) x { return _x; }
- xSet: (int) x{
	_x = x;
}
- (int) y { return _y; }
- ySet: (int) y{
	_y = y;
}
- (int) startedFromApp { return _startedFromApp; }
- startedFromAppSet: (int) startedFromApp{
	_startedFromApp = startedFromApp;
}


@end